package com.xjy.spring.thrift.zk;

import java.util.ArrayList;
import java.util.List;

import org.I0Itec.zkclient.ZkClient;

/**
 * thrift服务发现
 * @author xujieyang
 *
 */
public class ThriftServiceDiscover {
	private ZkClient zkClient;
	public ThriftServiceDiscover(String connectString, int sessionTimeout, int connectTimeout) {
		zkClient = new ZkClient(connectString, sessionTimeout, connectTimeout);
	}
	
	public synchronized List<String> discover(String rootPath) {
		List<String> info = new ArrayList<>();
		List<String> currentChilds = zkClient.getChildren(rootPath);
		for (String node : currentChilds) {
			// 获取子节点中的数据
			String data = zkClient.readData(rootPath + "/" + node);
			info.add(data);
		}
		return info;
	}
}
